package com.k2.exstrasensorytypredictor.dialogs;

import android.R.bool;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.k2.exstrasensorytypredictor.R.string;
import com.k2.exstrasensorytypredictor.interfaces.IMsgHandler;

public class MDialog {
	public static final int DIALOG_YES_NO = 100;
	public static final int DIALOG_OK = 101;
	
	public static final int ANSWER_YES = 0;
	public static final int ANSWER_NO = 1;
	public static final int ANSWER_ONE = 2;
	public static final int ANSWER_TWO = 3;
	
	private AlertDialog.Builder adb;
	
	IOnDialogButtonPressed handler;
	
//	private boolean isCancelable;
//	private boolean canReturnTheResult;
//	
//	private String dlgTitle;
//	
//	private String[] buttonCaptions;
//	
//	private int[] valuesToReturn;
//	
//	private int result = -1;
	
	public MDialog(Context ctx, IOnDialogButtonPressed handler, String message, String[] buttons, boolean isCancelable, int dialogType){
		this.handler = handler;
		adb = new AlertDialog.Builder(ctx);
		adb.setTitle(message);
		adb.setCancelable(isCancelable);
		if (buttons != null && buttons.length > 0){
			switch (dialogType) {
			case DIALOG_OK:
				adb.setPositiveButton(buttons[0], new OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						MDialog.this.handler.OnDialogButtonPressed(ANSWER_YES);
					}
				});
				break;
			case DIALOG_YES_NO:
				adb.setPositiveButton(buttons[0], new OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						MDialog.this.handler.OnDialogButtonPressed(ANSWER_YES);
					}
				});
				adb.setNegativeButton(buttons[1], new OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						MDialog.this.handler.OnDialogButtonPressed(ANSWER_NO);
					}
				});
				break;

			default:
				break;
			}
		}
	}
	
	public int showDialog(){
		if (adb != null){
			adb.show();
		}
		
		return 0;
	}
}
